<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewUserSelement extends JView
{
	function display($tpl = null)
	{
		global $mainframe, $option;

		//initialise variables
		$document	= & JFactory::getDocument();
		$db			= & JFactory::getDBO();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		
		//set vars
		$gid		= $user->gid;
		$level		= $ownuser->get('level_id');

		$filter_branch		= $mainframe->getUserStateFromRequest( $option.'.userselement.filter_branch', 'filter_branch', 0, 'int' );
		$filter_order		= $mainframe->getUserStateFromRequest( $option.'.userselement.filter_order', 'filter_order', 'u.username', 'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'.userselement.filter_order_Dir',	'filter_order_Dir',	'ASC', 'word' );
		$search 			= $mainframe->getUserStateFromRequest( $option.'.userselement.search', 'search', '', 'string' );
		//$search 			= $db->getEscaped( trim(JString::strtolower( $search ) ) );

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');

		//Get data from the model
		$model			= $this->getModel();
		$rows			= & $this->get( 'Data' );
		$pageNav		= & $this->get( 'Pagination' );

		$lists = array();

		if( ($gid >= 25) || ($level >= 5) )
		{
			//get branch list	
			$branches		= & $this->get( 'Branches' );
			
			//Build filter branch select list
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );"'); 
		}
		// search filter
		$lists['search']= $search;

		// table ordering
		$lists['order_Dir'] = $filter_order_Dir;
		$lists['order'] = $filter_order;

		//assign data to template
		$this->assignRef('rows' , $rows);
		$this->assignRef('pageNav' , $pageNav);
		$this->assignRef('lists', $lists);

		parent::display($tpl);
	}
}
